package logic

import (
	"context"
	"meituan-waimai/models/mysql"

	"meituan-waimai/meituanrpc/internal/svc"
	"meituan-waimai/meituanrpc/meituanrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *meituanrpc.OrderListRequest) (*meituanrpc.OrderListResponse, error) {
	// todo: add your logic here and delete this line
	var orderList []mysql.Order
	mysql.DB.Where("user_id = ?", in.UserId).Find(&orderList)

	var list []*meituanrpc.OrderList
	for _, order := range orderList {
		slice := meituanrpc.OrderList{
			OrderNo:        order.OrderNo,
			OrderTitle:     order.OrderTitle,
			UserId:         order.UserId,
			OrderAmount:    float32(order.OrderAmount),
			OrderPayStatus: int64(order.OrderPayStatus),
			OrderStatus:    order.OrderStatus,
		}
		list = append(list, &slice)
	}
	return &meituanrpc.OrderListResponse{
		List: list,
	}, nil
}
